#include <windows.h>
#include <iostream>
#include <tchar.h>
#include <cstdio>

using namespace std;
void StartClone(int nCloneID) {
    TCHAR szFilename[MAX_PATH];
    ::GetModuleFileName(nullptr, szFilename, MAX_PATH);
    TCHAR szCmdLine[MAX_PATH];
    _stprintf_s(szCmdLine, MAX_PATH, _T("\"%s\" %d child"), szFilename, nCloneID);
    STARTUPINFO si;
    ::ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    PROCESS_INFORMATION pi;
    cout << "Created child process with id: " << pi.dwProcessId << ", Command Line: " << szCmdLine << endl;
    ::CloseHandle(pi.hProcess);
    ::CloseHandle(pi.hThread);
}
void StartClone() {
    TCHAR szFilename[MAX_PATH];
    ::GetModuleFileName(nullptr, szFilename, MAX_PATH);
    TCHAR szCmdLine[MAX_PATH];
    _stprintf_s(szCmdLine, MAX_PATH, _T("\"%s\" child"), szFilename);
    STARTUPINFO si;
    ::ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    PROCESS_INFORMATION pi;
    cout << "Created child process with id: " << pi.dwProcessId << ", Command Line: " << szCmdLine << endl;
    ::CloseHandle(pi.hProcess);
    ::CloseHandle(pi.hThread);
}
int main() {
    DWORD dwIdThis = ::GetCurrentProcessId();
    DWORD dwVerReq = ::GetProcessVersion(dwIdThis);
    WORD wMajorReq = (WORD) (dwVerReq & 0xFFFF);
    WORD wMinorReq = (WORD) ((dwVerReq >> 16) & 0xFFFF);
    cout << "Process id: " << dwIdThis << ", requires OS: " << wMajorReq << "." << wMinorReq << endl;
    StartClone();
    StartClone(1);
    OSVERSIONINFOEX ovx;
    ::ZeroMemory(&ovx, sizeof(ovx));
    ovx.dwOSVersionInfoSize = sizeof(ovx);
    ::GetVersionEx((OSVERSIONINFO *) &ovx);
    cout << "OS Version: " << ovx.dwMajorVersion << "." << ovx.dwMinorVersion << endl;
    return 0;
}